package com.odianyun.hello.service.impl;


import com.odianyun.db.mybatis.Filter;
import com.odianyun.hello.mapper.SoTypeMapper;
import com.odianyun.hello.service.SoTypeService;
import com.odianyun.hello.model.PO.SoTypePO;
import com.odianyun.hello.model.VO.SoTypeVO;
import com.odianyun.project.query.PageQueryArgs;
import com.odianyun.project.query.QueryArgs;
import com.odianyun.project.support.base.db.Q;
import com.odianyun.project.support.base.service.OdyEntityService;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import javax.annotation.Resource;

import org.apache.ibatis.util.MapUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
public class SoTypeServiceImpl extends OdyEntityService<SoTypePO, SoTypeVO, PageQueryArgs, QueryArgs, SoTypeMapper> implements SoTypeService {
    @Resource
    private SoTypeMapper mapper;
    @Resource
    private RedisTemplate redisTemplate;

    private static final String key = "SO_TYPE_MAP";
    @Override
    protected SoTypeMapper getMapper() {
        return mapper;
    }

    @Override
    public Map<String , String> getSoType(){
        ValueOperations<String,Map<String,String>> operations = redisTemplate.opsForValue();
        Map<String,String> soTypeCache =operations.get(key);
        if (null != soTypeCache){
            return soTypeCache;
        }
        List<SoTypeVO> soTypeVOList = super.list(new Q("code","name"));
        soTypeCache = soTypeVOList.stream().collect(Collectors
                .toMap(SoTypeVO::getCode , SoTypeVO::getName));

        return soTypeCache;
    }
}
